package com.uah;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	Button btnCurrent;
	Button btnProspective;
	Button btnColleges;
	Button btnAthletics;
	Button btnMaps;
	Button btnNews;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //Find hard coded buttons
        //This could be changed to a dynamic layout using DynamicLayoutCreation calls
        btnCurrent = (Button)findViewById(R.id.btnCurrent);
        btnCurrent.setOnClickListener(btnListener);
        
        btnProspective = (Button)findViewById(R.id.btnProspective);
        btnProspective.setOnClickListener(btnListener);
        
        btnColleges = (Button)findViewById(R.id.btnColleges);
        btnColleges.setOnClickListener(btnListener);
        
        btnAthletics = (Button)findViewById(R.id.btnAthletics);
        btnAthletics.setOnClickListener(btnAthleticsListener);
        
        btnMaps = (Button)findViewById(R.id.btnMaps);
        btnMaps.setOnClickListener(btnListener);
        
        btnNews = (Button)findViewById(R.id.btnNews);
        btnNews.setOnClickListener(btnListener);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    //Open up chosen page
    private OnClickListener btnListener = new View.OnClickListener(){
    	@Override
    	public void onClick(View v){
    		Button buttonClicked = (Button)v;
    		@SuppressWarnings("rawtypes")
			Class goToClass = MainActivity.class;
    		if (buttonClicked == btnCurrent)
    			goToClass = CurrentStudents.class;
    		else if (buttonClicked == btnColleges)
    			goToClass = Colleges.class;
    		else if (buttonClicked == btnMaps)
    			goToClass = Maps.class;
    		Intent myIntent = new Intent(MainActivity.this, goToClass);
    		MainActivity.this.startActivity(myIntent);
    	}
    };
    
    //The Athletics button opens up the mobile version of the UAH Athletics webpage in the browser
	private OnClickListener btnAthleticsListener = new View.OnClickListener(){
    	@Override
    	public void onClick(View v){
    		Uri uri = Uri.parse("http://www.uahchargers.com/");
    		Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    		startActivity(intent);
    	}
    };
    
}
